/**
 * 转换枚举对象
 * @param data 数据源
 * @param startNum 起始数
 * @return {{}}
 */
const objectToEnum = (data, startNum = 0) => {
  let obj
  if(data instanceof Array) {
    //  数组
    obj = {}
    data.map((item) => {
      obj[startNum] = item
      obj[item] = startNum
      startNum += 1
    })
  } else if(typeof data === 'object') {
    //  对象,拷贝一份
    obj = JSON.parse(JSON.stringify(data))
    Object.keys(obj).map((item) => {
      obj[obj[item]] = item
    })
  } else {
    console.log('参数格式有误')
  }
  return obj
}
// let result = objectToEnum({ a:0, b:2 })
let result = objectToEnum(['a', 'c'])
console.log(result)

const guid = () => {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0,
      v = c == 'x' ? r : (r & 0x3 | 0x8)
    return v.toString(16)
  })
}
let uuid = guid() // "a1ca0f7b-51bd-4bf3-a5d5-6a74f6adc1c7"
console.log(uuid)
